<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Hello, world!</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/bootstrap-select.min.css">
    <link rel="stylesheet" href="../css/select2.min.css">
    <link rel="stylesheet" href="../css/select2-bootstrap4.min.css">

    <link rel="stylesheet" href="../css/style.css">
    <style>
        .bd-placeholder-img {
            font-size: 1.125rem;
            text-anchor: middle;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        @media (min-width: 768px) {
            .bd-placeholder-img-lg {
                font-size: 3.5rem;
            }
        }

        html,
        body {
            height: 100%;
        }

        body {
            padding-bottom: 40px;
            background-color: #fff;
        }

        .form-signin {
            width: 100%;
            max-width: 640px;
            margin: auto;
            padding: 15px;
        }

        .form-signin .checkbox {
            font-weight: 400;
        }

        .form-signin .form-control {
            position: relative;
            box-sizing: border-box;
            height: auto;
            padding: 10px;
            font-size: 16px;
        }

        .form-signin .form-control:focus {
            z-index: 2;
        }

        .form-signin input[type="email"] {
            margin-bottom: -1px;
            border-bottom-right-radius: 0;
            border-bottom-left-radius: 0;
        }

        .form-signin input[type="password"] {
            margin-bottom: 10px;
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }

        .sr-only2 {
            margin-top: 15px;
        }


        .logodiv img {
            width: 240px;
            margin: 0 auto;
            display: block;
        }

        .logodiv {
            text-align: center;
        }

        .logodiv h1 {
            font-size: 1.4rem;
            color: #03357a;
            margin-top: 20px;
            margin-bottom: 20px;
        }

        .logodiv h2 {
            font-size: 1.5rem;
            margin-bottom: 80px;
        }



        .fgtpaws {
            text-align: center;
            margin-top: 10px;
        }

        .btn {
            padding: 0.375rem 0.15rem
        }

        .btn-tiqu {
            width: 125px;
            margin: 0 auto;
            display: block;
        }

        .buytitle {
            font-size: 1.1rem;
            color: #03357a;
            margin-top: 20px;
        }

        .buytitle span {
            font-size: 1rem;
            color: #999;
        }

        .action-row button {
            margin-bottom: 15px;
        }

        .buysearch {
            font-size: smaller;
        }

        .formscreen .form-control-theme {
            font-size: smaller;
        }

        .action-row {
            position: fixed;
            width: 100%;
            bottom: 0;
            margin-top: 0;
            margin-bottom: 0;
            background: #fff;
            left: 0;
        }

        .container2 {
            padding: 15px;
            display: block;
            overflow: hidden;
        }

        .bootstrap-select {
            width: calc(100% - 0px) !important;
        }

        .formscreen .filter-option-inner-inner {
            font-size: smaller;
        }

        .myselect {
            width: calc(100% - 0px);
        }

        .btn-action:disabled {
            background: #D9D9DA !important;
            color: #808081 !important;
        }

        .buysearch {
            width: 100%;
            display: block;
        }
    </style>
</head>

<body>
    <div id="app">


        <div class="modal fade fullmodal show" style="display: block;background: #fff;" id="exampleModal" tabindex="-1"
            aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-dialog-scrollable">
                <div class="modal-content">
                    <div class="modal-body">
                        <div style="display: none;" class="logodiv">
                            <img class="bannerlogo pt-3" src="../image/logo.jpeg">
                            <h3 class="mt-3 mb-5">{{lan['Production_Receipt']}}</h3>
                        </div>
                        <div class="row  align-items-center">



                            <div class="col-12 col-sm-6 col-md-3">
                                <div class="d-flex bd-highlight align-items-center">
                                    <div class="p-2 bd-highligh  flex-shrink-0 filedlabel">{{lan['Date']}}</div>
                                    <div class="p-2 flex-grow-1 bd-highlight">
                                        <input type="date" v-model="searchdata.ArrivedDate"
                                            :placeholder="lan['Date_placeholder']"
                                            class="form-control form-control-theme" value="">
                                    </div>
                                </div>
                            </div>

                            <div class="col-12 col-sm-6 col-md-3">
                                <div class="d-flex bd-highlight align-items-center">
                                    <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Job_No']}}</div>
                                    <div class="p-2 flex-grow-1 bd-highlight">

                                        <input type="text" @change="getPartNum3(3);" id="JobNum"
                                            v-model.lazy="searchdata.JobNum" :placeholder="lan['Job_No_placeholder']"
                                            class="form-control form-control-theme" value="">

                                    </div>
                                </div>
                            </div>
                            <div class="col-12 col-sm-6 col-md-3">
                                <div class="d-flex bd-highlight align-items-center">
                                    <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Assembly']}}</div>
                                    <div class="p-2 flex-grow-1 bd-highlight">
                                        <input type="text" id="Assembly" v-model="searchdata.Assembly"
                                            :placeholder="lan['Assembly_placeholder']"
                                            class="form-control form-control-theme" value="">
                                    </div>
                                </div>
                            </div>

                            <div class="col-12 col-sm-6 col-md-3">
                                <div class="d-flex bd-highlight align-items-center">
                                    <div class="p-2 bd-highligh flex-shrink-0 filedlabel">
                                        {{lan['Part']}}/{{lan['Desc']}}</div>
                                    <div class="p-2 flex-grow-1 bd-highlight">
                                        <div style="border-bottom: 1px solid #D3D3D3;padding: 10px 3px;">
                                            <div>{{searchdata.PartNum}}</div>
                                            <div>{{searchdata.PartDescription}}</div>
                                        </div>

                                    </div>
                                </div>
                            </div>



                            <div class="col-12 col-sm-6 col-md-3">
                                <div class="d-flex bd-highlight align-items-center">
                                    <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Complete_Qty']}}
                                    </div>
                                    <div class="p-2 flex-grow-1 bd-highlight">
                                        <input @input="checkDecimal" type="number" v-model="searchdata.Complete_Qty"
                                            :placeholder="lan['Complete_Qty_placeholder']"
                                            class="form-control form-control-theme" value="">
                                    </div>
                                </div>
                            </div>


                            <div class="col-12 col-sm-6 col-md-3">
                                <div class="d-flex bd-highlight align-items-center">
                                    <div class="p-2 bd-highligh flex-shrink-0 filedlabel">
                                        {{lan['WareHouseCode']}}
                                    </div>
                                    <div class="p-2 flex-grow-1 bd-highlight">
                                        <select @change="binNumChange()" v-model="searchdata.WareHouseCode"
                                            id="warehousecodeselect"
                                            class="form-select myselect myselect3 form-control-theme"
                                            data-live-search="true">
                                            <option v-for="(item,index) in WareHouseCodeList" :key="index"
                                                :value="item.Warehse_WarehouseCode"
                                                :data-name="item.Warehse_WarehouseCode">
                                                {{item.Warehse_WarehouseCode}}</option>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="col-12 col-sm-6 col-md-3">
                                <div class="d-flex bd-highlight align-items-center">
                                    <div class="p-2 bd-highligh flex-shrink-0 filedlabel">
                                        {{lan['BinNum']}}
                                    </div>
                                    <div class="p-2 flex-grow-1 bd-highlight">
                                        <select data-native-menu="true" v-model="searchdata.BinNum" id="binnumselect"
                                            class="form-select myselect myselect4 form-control-theme"
                                            data-live-search="true">
                                            <option v-for="(item,index) in binNumList" :key="index"
                                                :value="item.WhseBin_BinNum">
                                                {{item.WhseBin_BinNum}}
                                            </option>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="col-12">
                                <div class="d-flex bd-highlight align-items-center">
                                    <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Producer']}}</div>
                                    <div class="p-2 flex-grow-1 bd-highlight">
                                        <input type="text" v-model="searchdata.name" disabled
                                            class="form-control form-control-theme" value="">
                                    </div>
                                </div>
                            </div>


                            <div class="col-12">
                                <div class="d-flex bd-highlight align-items-center">
                                    <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['LotNum']}}</div>
                                    <div class="p-2 flex-grow-1 bd-highlight">
                                        <input type="text" v-model.lazy="LotNum" id="LotNum" :disabled="is_lot != 1"
                                            class="form-control form-control-theme" value="">
                                    </div>
                                    <button v-if="is_lot == 1"
                                        style="padding-left: 2px;padding-right: 2px;margin-left: 5px; width: 100px;"
                                        type="button" @click="getPartNum(2);"
                                        class="btn btn-primary btn-sm">{{lan['GetLotNum']}} </button>
                                    <button v-if="is_lot == 1"
                                        style="padding-left: 2px;padding-right: 2px;margin-left: 5px; width: 100px;"
                                        type="button" 
                                        :class=" Batch_check ? 'btn-secondary':'btn-primary'"
                                        :disabled="Batch_check" 
                                        @click="BatchProperties();"
                                        class="btn   btn-sm"
                                        >{{lan['Batch_Properties']}}
                                    </button>
                                </div>
                            </div>

                            <div v-if="is_SerialNum == 1" class="col-12">
                                <div class="d-flex bd-highlight align-items-center">
                                    <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Generate_SN']}}</div>
                                    <div class="p-2 flex-grow-1 bd-highlight">
                                        <div class="row">
                                            <div class="col-6">
                                                <button
                                                    :disabled="is_SerialNum == 0 || (SNBaseDataType == 'MASK' && MaskType == 0) || SNBaseDataType == 'CHARACTER' || entryCheck"
                                                    style="width: 100%;" onclick="CreateSeren();" type="button"
                                                    tapmode="" class="btn  btn-sm"
                                                    :class=" is_SerialNum == 0 || (SNBaseDataType == 'MASK' && MaskType == 0) || SNBaseDataType == 'CHARACTER' || entryCheck ? 'btn-secondary':'btn-primary'">{{lan['Generate_SN']}}
                                                    <span>{{SelectedSerialNumbers.length}}</span></button>
                                            </div>
                                            <div class="col-6">
                                                <button
                                                    :disabled="is_SerialNum == 0 ||  (SNBaseDataType == 'MASK' && MaskType == 1) || createCheck"
                                                    style="width: 100%;" onclick="SaveSN();" type="button" tapmode=""
                                                    class="btn  btn-sm"
                                                    :class="is_SerialNum == 0 ||  (SNBaseDataType == 'MASK' && MaskType == 1) || createCheck ? 'btn-secondary':'btn-primary'">{{lan['Save_SN']}}
                                                </button>
                                            </div>
                                        </div>
                                        <!--                                        
                                        <select :disabled="is_SerialNum==0" id="site-content" v-model="searchdata.is_sn" class="form-select form-control-theme form-control"
                                            :placeholder="lan['Site_placeholder']" aria-label="Please select site">
                                            <option value="1">{{lan['YES']}}</option>
                                            <option value="0">{{lan['NO']}}</option>
                                        </select> -->
                                    </div>
                                </div>
                            </div>

                        </div>

                        <div class=" row justify-content-center mt-4">
                            <div class="col-4 col-md-4">
                                <button type="button" @click="getPartNum(1)" :disabled="receipt_check" tapmode=""
                                    class="btn btn-primary btn-action">{{lan['Comfirm']}}</button>
                            </div>


                            <div class="col-4 col-md-4">
                                <button type="button" tapmode="" onclick="close_win1()"
                                    class="btn btn-primary btn-action">{{lan['Cancel']}}</button>
                            </div>

                        </div>

                    </div>

                    <div class="modal-footer">
                        <div class="copyright">
                            <div class="row" :gutter="10">
                                <div class="col-5" style="text-align: right;">{{lan['Version']}}：</div>
                                <div class="col-7">{{appversion}}</div>
                                <div class="col-5" style="text-align: right;">{{lan['Site']}}：</div>
                                <div class="col-7">{{SiteName}}</div>
                                <div class="col-5" style="text-align: right;">{{lan['Company']}}：</div>
                                <div class="col-7">{{CompanyName}}</div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>


        <div class="container2">
            <div class="buysearch buysearch2">
                <table class="table table-buy table-borderless table-sm">
                    <tr>
                        <td class="ttl">{{lan['Date']}}</td>
                        <td class="ttl">{{lan['Job_No']}}</td>
                    </tr>
                    <tr>
                        <td> {{searchdata.ArrivedDate}}</td>
                        <td>{{searchdata.JobNum}}</td>
                    </tr>
                    <tr>
                        <td class="ttl">{{lan['Assembly']}}</td>
                        <td class="ttl">{{lan['Complete_Qty']}}</td>
                    </tr>
                    <tr>
                        <td>{{searchdata.Assembly}}</td>
                        <td> {{searchdata.Complete_Qty}} <span>{{searchdata.IUM}}</span></td>
                    </tr>

                    <tr>
                        <td class="ttl">{{lan['Part']}}</td>
                        <td class="ttl">{{lan['Lot']}}</td>
                    </tr>
                    <tr>
                        <td> {{searchdata.PartNum}}</td>
                        <td> {{LotNum}}</td>
                    </tr>

                </table>
            </div>
        </div>

        <div style="height:100px;"></div>
        <div class="action-row">
            <div class="container">
                <div class=" row align-items-center justify-content-center">
                    <div class="col-4 col-md-4">
                        <button type="button" @click="submitfrom()" :disabled="comfirm_btn" tapmode=""
                            class="btn btn-primary btn-action">{{lan['Comfirm']}}
                        </button>
                    </div>
                    <div v-if="is_SerialNum==1" class="col-4 col-md-4">
                        <button type="button" onclick="checkSn();" tapmode=""
                            class="btn btn-primary btn-action">{{lan['View_SN']}}
                        </button>
                    </div>


                    <div class="col-4 col-md-4">
                        <button type="button" tapmode="" @click="print_label()"
                            class="btn btn-primary btn-action">{{lan['Print_Label']}}
                        </button>
                    </div>

                </div>

            </div>

        </div>

        <div id="mylabel1" class="mylabel1">
            <h5 class="text-center d-flex"><span id="CompanyName">上海xxxx金属制品有限公司</span>
                <img class="printlogo" src="../image/logo2.jpeg">
            </h5>
            <div class="row">
                <div class="col-6 labeltxt"><span class="title">物料号：</span><span class="print_PartNum"></span></div>
                <div class="col-6 labeltxt"><span class="title">工单号：</span><span class="print_JobNum"></span></div>
                <div class="col-12 labeltxt"><span class="title">物料描述：</span><span class="print_OrderNum"></span></div>
                <div class="col-4 labeltxt"><span class="title">数量：</span><span class="print_TranQty"></span></div>
                <div class="col-5 labeltxt"><span class="title">批次号：</span><span class="print_LotNum"></span></div>
                <div class="col-3 labeltxt"><span class="title">版本：</span>{{version}}</div>
                <div id="print_qrcode" class="col-12">
                    <div class="qrcode1" id="qrcode1"></div>
                </div>
                <div class="col-12 labeltxt text-center print_LabelNum">

                </div>
            </div>

        </div>


    </div>

</body>
<script type="text/javascript" src="../script/lang.js"></script>
<script type="text/javascript" src="../script/model.js"></script>
<script type="text/javascript" src="../script/JsBarcode.all.min.js"></script>
<script type="text/javascript" src="../script/qrcode.min.js"></script>
<script type="text/javascript" src="../script/html2canvas.min.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue.min.js"></script>
<script type="text/javascript" src="../script/jquery.min.js"></script>
<script type="text/javascript" src="../script/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="../script/bootstrap-select.min.js"></script>
<script type="text/javascript" src="../script/select2/select2.min.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/goodprint.js"></script>
<script type="text/javascript">
    var postcount = 0;
    var returncount = 0;
    var postlist = [];
    var tags = [];
    var tags2 = [];
    var tagspostcount = 0;
    var submit_type = 1;

    const app = new Vue({
        el: '#app',
        data: {
            xlist: [],
            xlist2: [],
            tlist: [],
            tlist2: [],
            list1: [],
            list2: [],
            listids: [],
            WareHouseCodeList: [],
            binNumList: [],
            all1: 0,
            all2: 0,
            joblist: [],
            SelectedSerialNumbers: [],
            post: {},
            LotNum: '',
            is_lot: 0,
            is_SerialNum: 0,//0 不需要序列号 1 需要序列号
            SNFormats: "",
            SNPrefix: "",
            createCheck: false,
            entryCheck: false,
            SNBaseDataType: "",
            MaskType: 0,
            LotItem:{},
            screenwidth: document.body.clientWidth,
            vendors: [],
            SNFormat: [],
            searchdata: {
                name: '',
                JobNum: '',
                ArrivedDate: timenow(),
                Assembly: '0',
                WareHouseCode: '',
                BinNum: '',
                No_of_Carton: '',
                No_of_Palle: '',
                Tail_of_Carton: '',
                Tail_of_Palle: '',
                Qty_of_Palle: '',
                Complete_Qty: '',
                RevisionNum: '',
                ProdCode: '',
                OrderNum: '',
                NumOfDec: 0,
                AllowDecimals: false,
                IUM: '',
                PartNum: '',
                PartDescription: ''

            },
            uinfo: {},
            //postlist: [],
            //postlistids: [],
            batch_data: {
                PartNum: "",
                LotNum: ""
            },
            create_btn: false,
            receipt_btn: true,
            receipt_check: true,
            Batch_check: true,
            print_btn: true,
            print_btn1: false,
            print_btn2: false,
            print_sn: false,
            print_no: false,
            save_sn_btn: true,
            sn_btn: false,
            comfirm_btn: false,
            Lot_btn:false,
            attribute_btn:false,
            print_num: 1,
            version: '',
            item: {},
      
        },
        mounted() {
            const that = this
            window.onresize = () => {
                return (() => {
                    that.screenwidth = document.body.clientWidth
                    //init_select2();
                })()
            }

            this.showmodal();
            //init_select2();
            //init_select();
            setTimeout(function () {
                $("#JobNum").focus();
            }, 500);

        },
        methods: {
            binNumChange() {
                var vname = $('#warehousecodeselect option:selected').attr("data-name");
                loadBinData(vname)

            },
            checkDecimal() {
                // 获取输入框的值
                let inputValue = this.searchdata.Complete_Qty;
                let parsedValue = parseFloat(inputValue);
                if (!isNaN(parsedValue)) {
                    const decimalCount = (inputValue.toString().split('.')[1] || "").length || 0;
                    if (decimalCount > this.searchdata.NumOfDec) {
                        // 超过 NumOfDec 位小数，截取前 NumOfDec 位小数，不进行四舍五入
                        inputValue = inputValue.substring(0, inputValue.indexOf('.') + this.searchdata.NumOfDec + 1);
                    }
                    this.searchdata.Complete_Qty = inputValue;
                }
            },

            remove: function (index) {
                this.list.splice(index, 1);
            },
            //点击批次属性跳转页面
            BatchProperties: function () {
                let that = this
                let PartNum = app.searchdata.PartNum
                if (!app.searchdata.Complete_Qty) {
                    api.toast({
                        msg: lan['Complete_Qty_placeholder'],
                        location: 'middle'
                    });
                    return false;

                }
                if(!app.LotNum){
                    api.toast({
                        msg:lan['Please_Lot_nunber'],
                        location: 'middle'
                    });
                    return false;
                }
                if (PartNum != '' && app.LotNum != '') {
                    var data = {};
                    data.item = app.LotItem;
                    data.PartNum = PartNum;
                    data.type = "Production"
                    data.LotNum = app.LotNum;
                    data.Lot_btn = app.Lot_btn;
                    data.attribute_btn =app.attribute_btn
                    data.Batch_check = app.Batch_check
                    data.title = lan['Batch_Properties'];
                    data.frame = "batch_properties";
                    openNavWin2(data.frame, data);
                    that.receipt_check = false
                }
            },
            print_label: function () {
                var btns = [];
                if (this.receipt_btn) {
                    btns.push(lan['Print_Carton_Label']);//打印箱条码
                }
                if (this.is_SerialNum == 1) {
                    btns.push(lan['Print_SN_Label']); //打印物料条码
                }
                btns.push(lan['Print_NO_SN_Label'])//打印外部产品标签
                var that = this;
                api.actionSheet({
                    title: lan['Tips'],
                    cancelTitle: lan['Cancel'],
                    buttons: btns
                }, function (ret, err) {
                    var index = ret.buttonIndex;
                    var key = index - 1;

                    if (btns[key] == lan['Print_Carton_Label']) {
                        print_type = 2;
                        that.print_carton();
                    }
                    if (btns[key] == lan['Print_SN_Label']) {
                        print_type = 1;
                        that.submit_sncode();
                    }
                    if (btns[key] == lan['Print_NO_SN_Label']) {
                        print_type = 1;
                        that.submit_nocode();

                    }
                });
            },
            submit_nocode: function () {
                print_index = 0;
                print_tags = [];
                print_codes = [];

                for (i in this.list1) {
                    if (this.list1[i].is_check) {
                        print_codes.push(this.xlist2[i]);
                    }
                }
                let ExpiryDate = api.getPrefs({
                    sync: true,
                    key: 'ExpiryDate'
                })
                if (print_codes.length > 0) {

                    for (i in print_codes) {
                        print_codes[i].CountryCode_c = "China";
                        print_codes[i].version = this.searchdata.RevisionNum;
                        print_codes[i].ProdCode = this.searchdata.ProdCode
                        print_codes[i].ExpiryDate = ExpiryDate
                   
                        if (this.searchdata.OrderNum != '') {
                            print_codes[i].OrderNum = this.searchdata.OrderNum;
                        }


                    }
                    let result = print_codes.reduce(function (acc, item) {
                        let TranQty = item.TranQty;
                        let rest = Object.assign({}, item);
                        delete rest.TranQty;
                        return acc.concat(Array(Number(TranQty)).fill(Object.assign({ TranQty: 1 }, rest)));
                    }, []);
                    print_tags = result;
                    open_printpage4(print_tags, 1, 3, print_codes);
                    api.removePrefs({
                        key: 'ExpiryDate'
                    });
                }
            },
            submit_sncode: function () {
                print_index = 0;
                print_tags = [];

                print_tags = this.SelectedSerialNumbers;
                if (this.searchdata.OrderNum != '') {
                    this.SelectedSerialNumbers[0].OrderNum = this.searchdata.OrderNum;
                }
                if (this.searchdata.JobNum != '') {
                    this.SelectedSerialNumbers[0].JobNum = this.searchdata.JobNum;
                }
                this.SelectedSerialNumbers[0].version = this.searchdata.RevisionNum;
                open_printpage(print_tags, 1, 3);
            },

            print_carton: function () {
                print_index = 0;
                print_tags = [];
                console.log(JSON.stringify(this.list1), 8888899)
                for (i in this.list1) {
                    print_tags.push(this.list1[i]);
                  
                }
                let ExpiryDate = api.getPrefs({
                    sync: true,
                    key: 'ExpiryDate'
                })
                if (print_tags.length > 0) {

                    for (i in print_tags) {
                        print_tags[i].CountryCode_c = "中國 China";
                        print_tags[i].ExpiryDate = ExpiryDate
                        print_tags[i].version = this.searchdata.RevisionNum;
                        print_tags[i].ProdCode = this.searchdata.ProdCode;
                        print_tags[i].JobNum = this.searchdata.JobNum;
                        print_tags[i].OnhandQty = this.searchdata.Complete_Qty;
                        print_tags[k].LabelNum =  print_tags[i].JobHead_PartNum + "/" + this.searchdata.LotNum;
                        print_tags[i].LotNum = this.searchdata.LotNum;
                        print_tags[i].IUM = this.searchdata.IUM;
                        if (this.searchdata.OrderNum != '') {
                            print_tags[i].OrderNum = this.searchdata.OrderNum;
                        }


                    }

                    console.log(JSON.stringify(print_tags), 66666)
                    open_printpage2(print_tags, 1, 1, 2, 0);
                    api.removePrefs({
                        key: 'ExpiryDate'
                    });
                }
            },
            start_print: function (ptype) {
                api.prompt({
                    title: lan['Print_Label_Num'],
                    type: 'number',
                    text: 1,
                    buttons: [lan['Print_Label'], lan['Cancel']]
                }, function (ret, err) {
                    var index = ret.buttonIndex;
                    if (index == 1) {
                        print_num = parseInt(ret.text);
                        if (print_num > 0) {
                            if (ajaxing) { return; } showProgress(lan['Loading']);
                            if (ptype == 1) {
                                wificonnect();
                            } else {
                                wificonnect2();
                            }

                        }

                    }

                });
            },
            
            showmodal: function () {
                if (this.screenwidth < 576) {
                    $('#exampleModal').modal('show');
                    //init_select();
                } else {

                    $('#JobNum').focus();
                }
            },
            hidemodal: function () {
                $('#exampleModal').modal('hide');
            },
        }
    });

    async function loadWarehouseCodeData() {
        userinfo = get_user_info();
        if (!userinfo.Token) {
            return;
        }
        $('.myselect3').selectpicker('destroy'); // 先销毁
        app.WareHouseCodeList = [];
        await api.ajax({
            url: server + 'BaqSvc/WMS_WarehouseForPart/?CompID=' + userinfo.Company + "&Site=" + userinfo.Site + "&PartNum=" +app.searchdata.PartNum,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {}
        }, function (ret, err) {
            if (ret && ret.value.length > 0) {
                app.WareHouseCodeList = app.WareHouseCodeList.concat(ret.value)
                setTimeout(function () {
                    $('.myselect3').selectpicker('refresh');//在更新
                }, 200)
                console.log(JSON.stringify(app.WareHouseCodeList), 22222)

            }
        });
    }
    async function loadBinData(value) {
        userinfo = get_user_info();
        $('.myselect4').selectpicker('destroy'); // 先销毁
        await api.ajax({
            url: server + 'BaqSvc/WMS_WhseBin/?CompID=' + userinfo.Company + "&WarehouseCode=" + value,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {

            }
        }, function (ret, err) {
            if (ret && ret.value.length > 0) {
                app.binNumList = app.binNumList.concat(ret.value)
                setTimeout(function () {
                    $('.myselect4').selectpicker('refresh');//在更新
                }, 200)
                console.log(JSON.stringify(app.binNumList), 22222)
            }

        });
    }

    apiready = function () {
        api.parseTapmode();
        server = getapi();
        $('.myselect').selectpicker();
        //back_listen();
        api.addEventListener({ name: 'navitembtn' }, function (ret, err) {
            if (ret.type == 'left') { close_win1(); }
            if (ret.type == 'right') { scan2(); }

        });
        app.vendors = get_prefs_data("Vendors");
        app.joblist = get_prefs_data("JobNum");
        if (!app.joblist) {
            loadJobData();
        }

        app.uinfo = get_user_info();
        userinfo = get_user_info();
        app.searchdata.name = userinfo.Name;
        setTimeout(function () {
            $('.myselect').selectpicker('refresh');
        }, 500);

        api.addEventListener({
            name: 'infrared_scanning'
        }, function (ret, err) {
            console.log(JSON.stringify(ret));
            app.searchdata.JobNum = ""
            if (ret && ret.value && ret.value.str) {
                var val1 = $("input:focus").val();
                val1 = val1 ? val1 : '';
                val1 = val1 + ret.value.str;
                $("input:focus").val(val1);
                app.searchdata.JobNum = ret.value.str;
                app.LotNum = $("#LotNum").val();
                getPartNum3(3)

            }

        });
        api.addEventListener({
            name: 'keyback',
            extra: {
                slidBackIntercept: true
            }
        }, function (ret, err) {
            close_win1()

        });

        api.addEventListener({
            name: 'job_sn_update'
        }, function (ret, err) {
            if (ret && ret.value) {
                var snposts1 = ret.value;
                snposts = JSON.parse(snposts1);
                console.log(JSON.stringify(snposts), 55555)
                app.item.snsCheck = snposts[0].snsCheck;
                app.SelectedSerialNumbers = snposts[0].SelectedSerialNumbers;
                api.closeWin({ name: 'job_sn' });
            }
        });

        api.addEventListener({
            name: 'batch_properties_update'
        }, function (ret, err) {
            if (ret && ret.value) {
                var snposts1 = ret.value;
                console.log(JSON.stringify(snposts1), 55555)
                app.Lot_btn = snposts1.Lot_btn
                app.attribute_btn = snposts1.attribute_btn
                api.closeWin({ name: 'batch_properties' });
            }
        });



    }
    //关闭取消事件
    function close_win1() {
        if (app.comfirm_btn == false) {
            api.confirm({
                title: lan['Tips'],
                msg: lan['Production_Receipt_cancel_tips'],
                buttons: [lan['NO'], lan['YES'], lan['Cancel']]
            }, function (ret, err) {
                var index = ret.buttonIndex;
                if (index == 2) {
                    submitfrom();
                } else if (index == 1) {
                    close_win();
                }
            });

        } else {
            close_win();
        }


    }

    // app.post.PartNum
    function checkData() {
        return new Promise(function (resolve, reject) {
            if (!app.searchdata.ArrivedDate) {
                api.toast({
                    msg: lan['Date_placeholder'],
                    location: 'middle'
                });
                reject();
                return;
            }
            if (!app.searchdata.JobNum) {
                api.toast({
                    msg: lan['Job_No_placeholder'],
                    location: 'middle'
                });
                reject();
                return;
            }
            if (app.searchdata.Assembly.length == 0) {
                api.toast({
                    msg: lan['Assembly_placeholder'],
                    location: 'middle'
                });
                reject();
                return;
            }
            if (!app.searchdata.Complete_Qty) {
                api.toast({
                    msg: lan['Complete_Qty_placeholder'],
                    location: 'middle'
                });
                reject();
                return;
            }
            if (app.is_lot == 1) {
                console.log(app.LotNum, 44444)
                if (!app.LotNum) {
                    api.toast({
                        msg: lan['LotNum_placeholder'],
                        location: 'middle'
                    });
                    hideProgress();
                    reject();
                    return;
                }
            }
            resolve();
        });
    }
    async function CreateSeren() {
        await checkData()
        console.log(JSON.stringify(app.SelectedSerialNumbers), 222222)
        console.log(JSON.stringify(app.SelectedSerialNumbers.length), 333333)
        console.log(app.comfirm_btn, 55555)
        let item = app.item
        app.item.SelectedSerialNumbers = app.SelectedSerialNumbers
        app.item.tags = app.xlist2;
        if (app.comfirm_btn) {
            console.log(app.comfirm_btn, 66666)
            var data = {};
            console.log(JSON.stringify(app.xlist2), 111111)

            var k = 1;
            for (i in item.SelectedSerialNumbers) {
               
                item.SelectedSerialNumbers[i]['xs'] = k;
                item.SelectedSerialNumbers[i]['type'] = 1;
              
            }
            var arr = [];
            arr.push(item)
            data.list = arr;
            data.title = lan['Generate_SN'];
            data.receipt_btn = app.receipt_btn;
            data.SNFormat = app.SNFormats;
            data.SNPrefix = app.SNPrefix;
            data.createCheck = app.createCheck;
            data.entryCheck = app.entryCheck;
            data.confirm_btn = app.comfirm_btn;
            data.SNBaseDataType = app.SNBaseDataType;
            data.searchdata = app.searchdata;
            data.xlist2 = app.xlist2
            data.MaskType = app.MaskType;
            data.frame = "job_sn";
            openNavWin2(data.frame, data);
        } else {
            console.log(this.comfirm_btn, 77777)
            if (item.SelectedSerialNumbers.length == 0) {
                CreateSn()
            } else {
                var data = {};
                var oneQty = parseInt(app.searchdata.Qty_Per_Carton);
                var k = 1;
                for (i in item.SelectedSerialNumbers) {
                    item.SelectedSerialNumbers[i]['xs'] = k;
                    item.SelectedSerialNumbers[i]['type'] = 1;
                  
                }
                var arr = [];
                arr.push(item)
                data.list = arr;
                data.title = lan['Generate_SN'];
                data.receipt_btn = app.receipt_btn;
                data.SNFormat = app.SNFormats;
                data.SNPrefix = app.SNPrefix;
                data.createCheck = app.createCheck;
                data.entryCheck = app.entryCheck;
                data.confirm_btn = app.comfirm_btn;
                data.searchdata = app.searchdata;
                data.xlist2 = app.xlist2
                data.SNBaseDataType = app.SNBaseDataType;
                data.MaskType = app.MaskType;
                data.frame = "job_sn";
                openNavWin2(data.frame, data);
            }
        }

    }
    function CreateSn() {
        var data1 = {
            "CompanyID": userinfo.Company,
            "PlantID": userinfo.Site,
            "UserName": userinfo.Name,
            "Password": userinfo.password,
            "TranDate": app.searchdata.ArrivedDate,
            "TranQty": app.searchdata.Complete_Qty,
            "JobNum": app.searchdata.JobNum,
            "AssemblySeq": app.searchdata.Assembly,
            "LotNum": app.LotNum,
        }
        api.ajax({
            url: wmsserver + 'snjobtoinv/',
            method: 'post',
            returnAll: false,
            headers: {
                'token': wmstoken,
                'Content-Type': 'application/json;charset=utf-8'
            },
            //dataType: 'text',
            data: {
                body: create_submit_data(data1)
            }
            //data: {values: data1}
        }, function (ret, err) {
            ajaxing = 0;
            console_debug(ret, err);
            hideProgress();
            if (ret && ret.code == 1) {
                var count = processNumber(app.searchdata.No_of_Carton, app.searchdata.NumOfDec);
                var oneQty = processNumber(app.searchdata.Qty_Per_Carton, app.searchdata.NumOfDec);
                var snno = ret.data.SelectedSerialNumbers;
                console_debug(snno, 'SelectedSerialNumbers');
                app.SelectedSerialNumbers = snno;
                app.SNFormat = ret.data.SNFormat;
                app.createCheck = true;
                setTimeout(function () {
                    let item = app.item
                    app.item.SelectedSerialNumbers = app.SelectedSerialNumbers
                    app.item.tags = app.xlist2;
                    var data = {};
                    var arr = [];
                    var oneQty = parseInt(app.searchdata.Qty_Per_Carton);
                    arr.push(item)
                    data.list = arr;
                    data.title = lan['Generate_SN'];
                    data.receipt_btn = app.receipt_btn;
                    data.SNFormat = app.SNFormats;
                    data.SNPrefix = app.SNPrefix;
                    data.createCheck = app.createCheck;
                    data.entryCheck = app.entryCheck;
                    data.confirm_btn = app.comfirm_btn;
                    data.searchdata = app.searchdata;
                    data.SNBaseDataType = app.SNBaseDataType;
                    data.MaskType = app.MaskType;
                    data.frame = "job_sn";
                    openNavWin2(data.frame, data);
                }, 200)
            } else {
                hideProgress();
                errMassage(ret.msg)
            }

        });
    }

    function checkSn() {
        let item = app.item
        app.item.SelectedSerialNumbers = app.SelectedSerialNumbers
        app.item.tags = app.xlist2
        console.log(JSON.stringify(item), 88888)
        var data = {};
        var arr = [];
        app.entryCheck = true;
        if (item.SelectedSerialNumbers.length != 0) {
            var count = processNumber(app.searchdata.No_of_Carton, app.searchdata.NumOfDec);
            var oneQty = processNumber(app.searchdata.Qty_Per_Carton, app.searchdata.NumOfDec);
            var InputOurQty = processNumber(app.searchdata.Complete_Qty, app.searchdata.NumOfDec);
            let tailQty = processNumber(InputOurQty % oneQty, app.searchdata.NumOfDec);
            data.title = lan['Save_SN'];
            data.right = [{
                text: lan["Scan"],
                color: '#fff',
            }];
            var k1 = 1;
            for (i in item.SelectedSerialNumbers) {
                item.SelectedSerialNumbers[i]['xs'] = k1;
                item.SelectedSerialNumbers[i]['OnhandQty'] = InputOurQty
                item.SelectedSerialNumbers[i]['type'] = 1;
                var i1 = parseInt(i) + 1;
                if (i1 % oneQty == 0) {
                    k1++;
                }
            }
            arr.push(item)
            data.list = arr;
            data.key = 1;
            data.SNFormat = app.SNFormats;
            data.SNPrefix = app.SNPrefix;
            data.createCheck = app.createCheck;
            data.entryCheck = app.entryCheck;
            data.receipt_btn = true;
            data.SNBaseDataType = app.SNBaseDataType;
            data.MaskType = app.MaskType;
            data.confirm_btn = app.confirm_btn
            data.searchdata = app.searchdata
            data.ImportNum = app.searchdata.ImportNum
            data.frame = "job_sn";
            data.PackSlip = app.searchdata.PackSlip
            openNavWin2(data.frame, data);
        }
    }

    async function SaveSN() {
        await checkData()
        let item = app.item
        app.item.SelectedSerialNumbers = app.SelectedSerialNumbers
        app.item.tags = app.xlist2
        console.log(JSON.stringify(item), 88888)
        var data = {};
        var arr = [];
        app.entryCheck = true;
        if (item.SelectedSerialNumbers.length != 0) {
            arr.push(item)
            data.list = arr;
            data.key = 1;
            data.title = lan['Save_SN'];
            data.right = [{
                text: lan["Scan"],
                color: '#fff',
            }];
            var oneQty = processNumber(app.searchdata.Qty_Per_Carton, app.searchdata.NumOfDec);
            var k1 = 1;
            for (i in item.SelectedSerialNumbers) {
                item.SelectedSerialNumbers[i]['xs'] = k1;
                var i1 = parseInt(i) + 1;
                if (i1 % oneQty == 0) {
                    k1++;
                }
            }
            data.SNFormat = app.SNFormats;
            data.SNPrefix = app.SNPrefix;
            data.createCheck = app.createCheck;
            data.entryCheck = app.entryCheck;
            data.SNBaseDataType = app.SNBaseDataType;
            data.MaskType = app.MaskType;
            data.searchdata = app.searchdata
            data.confirm_btn = app.confirm_btn
            data.ImportNum = app.searchdata.ImportNum
            data.frame = "job_sn";
            data.PackSlip = app.searchdata.PackSlip
            openNavWin2(data.frame, data);
        } else {
            if (app.comfirm_btn) {
            ;
                var InputOurQty = processNumber(app.searchdata.Complete_Qty, app.searchdata.NumOfDec);
                var k1 = 1;

                for (i in item.SelectedSerialNumbers) {
                    tag.ProdCode = item.ProdCode;
                    item.SelectedSerialNumbers[i]['xs'] = k1;
                    item.SelectedSerialNumbers[i]['type'] = 1;
                    item.SelectedSerialNumbers[i]['OnhandQty'] = InputOurQty
                }
                arr.push(item)
                console.log(JSON.stringify(arr), 22222)
                data.list = arr;
                data.key = 0;
                data.title = lan['Save_SN'];
                data.SNFormat = app.SNFormats;
                data.SNPrefix = app.SNPrefix;
                data.createCheck = app.createCheck;
                data.confirm_btn = app.comfirm_btn;
                data.entryCheck = app.entryCheck;
                data.searchdata = app.searchdata;
                data.xlist2 = app.xlist2
                data.PackSlip = app.searchdata.PackSlip
                data.SNBaseDataType = app.SNBaseDataType;
                data.MaskType = app.MaskType;
                data.frame = "job_sn";
                openNavWin2(data.frame, data);

            } else {
                console.log(JSON.stringify(app.xlist2), 44444)
                var count = processNumber(app.searchdata.No_of_Carton, app.searchdata.NumOfDec);
                var InputOurQty = processNumber(app.searchdata.Complete_Qty, app.searchdata.NumOfDec);
                for (let i = 0; i < InputOurQty; i++) {
                    item.SelectedSerialNumbers.push({
                        'xs': k1,
                        'type': 1,
                        'OnhandQty': InputOurQty,
                        'SerialNumber': '',
                        'SNBaseNumber': '',
                        'RawSerialNum': ''
                    })
                }
                arr.push(item)
                console.log(JSON.stringify(item), 444444)
                data.list = arr;
                data.key = 0;
                data.title = lan['Save_SN'];
                data.right = [{
                    text: lan["Scan"],
                    color: '#fff',
                }];
                data.SNFormat = app.SNFormats;
                data.SNPrefix = app.SNPrefix;
                data.createCheck = app.createCheck;
                data.entryCheck = app.entryCheck;
                data.SNBaseDataType = app.SNBaseDataType;
                data.MaskType = app.MaskType;
                data.confirm_btn = app.comfirm_btn;
                data.searchdata = app.searchdata;
                data.xlist2 = app.xlist2
                data.ImportNum = app.searchdata.ImportNum
                data.frame = "job_sn";
                data.PackSlip = app.searchdata.PackSlip
                openNavWin2(data.frame, data);

            }

        }

    }


    function loadJobData() {
        userinfo = get_user_info();
        if (!userinfo.Token) {
            return;
        }
        api.ajax({
            url: server + 'Erp.BO.JobEntrySvc/List',
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {
                values: {
                    '$select': 'JobNum,PartNum,DrawNum',
                    '$filter': "Company eq '" + userinfo.Company + "'"
                }
            }
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                api.setPrefs({
                    key: 'JobNum',
                    value: ret.value
                });
                app.joblist = ret.value;
            }

        });
    }

    function scan2() {

        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    //alert(ret.content);
                    var val1 = $("input:focus").val()
                    val1 = val1 ? val1 : '';
                    val1 = val1 + ret.content;
                    $("input:focus").val(val1);
                    if(!app.searchdata.JobNum){
                        app.searchdata.JobNum = ret.content;
                        getPartNum3(3)
                    }else{
                        if(!app.searchdata.WarehouseCode){
                            app.searchdata.WarehouseCode = ret.content;
                            $('#warehousecodeselect').val(app.searchdata.WarehouseCode).trigger("change");
                        }else{
                            app.searchdata.BinNum = ret.content;
                            $('#binnumselect').val(app.searchdata.BinNum).trigger("change");
                        }
                    }
                    
                    app.LotNum = $("#LotNum").val();
                   
                }

            } else {
                //alert(JSON.stringify(err));
            }
        });
    }


    function scan() {

        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    //alert(ret.content);
                    app.searchdata.JobNum = ret.content
                }

            } else {
                //alert(JSON.stringify(err));
            }
        });
    }
    function getPartNum3(type) {

        submit_type = type;

        if (!app.searchdata.JobNum) {
            api.toast({
                msg: lan['Job_No_placeholder'],
                location: 'middle'
            });
            return false;
        }

        if (ajaxing) { return; } showProgress(lan['Loading']);
        api.ajax({
            url: server + 'BaqSvc/WMS_Job/?CompID=' + userinfo.Company + '&Site=' + userinfo.Site + '&JobNum=' + app.searchdata.JobNum,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {}
        }, function (ret, err) {
            ajaxing = 0;
            console_debug(ret, err);
            if (ret && ret.value.length > 0) {
                console.log(app.searchdata.JobNum,88888)
                console.log(JSON.stringify(ret), 9999999)
                app.post.PartNum = ret.value[0].JobHead_PartNum;
                app.post.RevisionNum = ret.value[0].JobHead_RevisionNum
                app.post.ProdCode = ret.value[0].ProdCode
                app.searchdata.RevisionNum = ret.value[0].RevisionNum
                app.searchdata.ProdCode = ret.value[0].ProdCode
                app.searchdata.OrderNum = ret.value[0].Calculated_OrderNum
                app.searchdata.NumOfDec = ret.value[0].UOM_NumOfDec
                app.searchdata.PartNum = ret.value[0].JobHead_PartNum;
                app.searchdata.PartDescription = ret.value[0].JobHead_PartDescription;
                app.searchdata.AllowDecimals = ret.value[0].UOM_AllowDecimals
                app.searchdata.IUM = ret.value[0].JobHead_IUM
                app.list1 = init_list(ret.value);
                app.list2 = init_list(ret.value);
                if (ret.value[0].Part_TrackLots) {
                    app.is_lot = 1;

                } else {
                    app.is_lot = 0;
                    app.receipt_check = false

                }
                app.SNPrefix = ret.value[0].Part_SNPrefix;
                app.SNFormats = ret.value[0].Part_SNFormat;
                app.SNBaseDataType = ret.value[0].Part_SNBaseDataType;
                app.MaskType = ret.value[0].SerialMask_MaskType;
                if (ret.value[0].Part_TrackSerialNum) {
                    app.is_SerialNum = 1;

                } else {
                    app.is_SerialNum = 0;
                    app.searchdata.is_sn = 0;

                }

                if (submit_type == 3) {
                    loadWarehouseCodeData()
                    hideProgress();
                    return;
                }

                if (submit_type == 1) {
                    if (app.is_SerialNum == 1) {
                        submitfrom()
                    } else {
                        submitfrom()
                    }
                } else {
                    if (ret.value[0].Part_TrackLots) {
                        app.batch_data.PartNum = ret.value[0].JobHead_PartNum;
                        LotAttributeOption(app.post);
                        GenerateNewLotNum(app.post);
                    } else {
                        api.toast({
                            msg: lan['NoNeedLotNum'],
                            location: 'middle'
                        });
                        hideProgress();
                    }
                }


            } else {
                hideProgress();
                api.toast({
                    msg: lan['Invalid_Job_Number'],
                    location: 'middle'
                });
            }

        });
    }
    function init_list(data) {
        for (i in data) {
            data[i].PartNum = data[i].JobHead_PartNum;
            data[i].JobNum = data[i].JobHead_JobNum;
            data[i].Company = data[i].JobHead_Company;
            data[i].PartDescription = data[i].JobHead_PartDescription;
            data[i].IUM = data[i].JobHead_IUM
        }
        return data;
    }


    function getPartNum(type) {
        console.log(type, "2233")
        submit_type = type;

        if (!app.searchdata.ArrivedDate) {
            api.toast({
                msg: lan['Date_placeholder'],
                location: 'middle'
            });
            return false;
        }
        if (!app.searchdata.JobNum) {
            api.toast({
                msg: lan['Job_No_placeholder'],
                location: 'middle'
            });
            return false;
        }
        if (app.searchdata.Assembly.length == 0) {
            api.toast({
                msg: lan['Assembly_placeholder'],
                location: 'middle'
            });
            return false;
        }
        if (!app.searchdata.Complete_Qty) {
            api.toast({
                msg: lan['Complete_Qty_placeholder'],
                location: 'middle'
            });
            return false;

        }
        if (ajaxing) { return; } showProgress(lan['Loading']);
        api.ajax({
            url: server + 'BaqSvc/WMS_Job/?CompID=' + userinfo.Company + '&Site=' + userinfo.Site + '&JobNum=' + app.searchdata.JobNum,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {}
        }, function (ret, err) {
            ajaxing = 0;
            console.log(JSON.stringify(ret), 11111)
            console_debug(ret, err);
            if (ret) {
                app.post.PartNum = ret.value[0].JobHead_PartNum;
                app.post.RevisionNum = ret.value[0].JobHead_RevisionNum
                app.post.ProdCode = ret.value[0].ProdCode
                app.searchdata.RevisionNum = ret.value[0].JobHead_RevisionNum
                app.searchdata.ProdCode = ret.value[0].ProdCode
                app.searchdata.OrderNum = ret.value[0].Calculated_OrderNum
                app.item.PartNum = ret.value[0].JobHead_PartNum;
                app.item.RevisionNum = ret.value[0].JobHead_RevisionNum
                app.item.ProdCode = ret.value[0].ProdCode
                app.item.JobNum = ret.value[0].JobHead_JobNum
                app.item.AssemblySeq = ret.value[0].AssemblySeq
                let InputOurQty = processNumber(app.searchdata.Complete_Qty, app.searchdata.NumOfDec);
                app.item.InputOurQty = InputOurQty
                app.item.totalQty = InputOurQty
                app.item.OnhandQty = InputOurQty
                app.item.snsCheck = false
                if (ret.value[0].Part_TrackLots) {
                    app.is_lot = 1;

                } else {
                    app.is_lot = 0;
                    app.receipt_check = false

                }
                app.SNPrefix = ret.value[0].Part_SNPrefix;
                app.SNFormats = ret.value[0].Part_SNFormat;
                app.SNBaseDataType = ret.value[0].Part_SNBaseDataType;
                app.MaskType = ret.value[0].SerialMask_MaskType;
                if (ret.value[0].Part_TrackSerialNum) {
                    app.is_SerialNum = 1;

                } else {
                    app.is_SerialNum = 0;
                    app.searchdata.is_sn = 0;

                }

                if (submit_type == 3) {
                    hideProgress();
                    return;
                }

                if (submit_type == 1) {
                    if (app.is_SerialNum == 1) {
                        submitfrom()
                    } else {
                        submitfrom()
                    }
                } else {
                    if (ret.value[0].Part_TrackLots) {
                        app.batch_data.PartNum = ret.value[0].Part_TrackLots
                        LotAttributeOption(app.post);
                        GenerateNewLotNum(app.post);
                    } else {
                        api.toast({
                            msg: lan['NoNeedLotNum'],
                            location: 'middle'
                        });
                        hideProgress();
                    }
                }
            } else {
                hideProgress();
                api.toast({
                    msg: 'PartNum Error',
                    location: 'middle'
                });
            }

        });
    }



    function submitfrom() {
        console.log(JSON.stringify(app.searchdata), 444444)
        if (!app.searchdata.ArrivedDate) {
            api.toast({
                msg: lan['Date_placeholder'],
                location: 'middle'
            });
            hideProgress();
            return false;
        }
        if(!app.attribute_btn && !app.Batch_check){
            api.toast({
                msg: lan['Lot_Attribute_placeholder'],
                location: 'middle'
            });
            hideProgress();
            return false; 
        }
        if (!app.searchdata.JobNum) {
            api.toast({
                msg: lan['Job_No_placeholder'],
                location: 'middle'
            });
            hideProgress();
            return false;
        }
        if (app.searchdata.Assembly.length == 0) {
            api.toast({
                msg: lan['Assembly_placeholder'],
                location: 'middle'
            });
            hideProgress();
            return false;
        }

        if (!app.searchdata.Complete_Qty) {
            api.toast({
                msg: lan['Complete_Qty_placeholder'],
                location: 'middle'
            });
            hideProgress();
            return false;

        }
        if (!app.searchdata.WareHouseCode) {
            api.toast({
                msg: lan['WareHouseCode_placeholder'],
                location: 'middle'
            });
            hideProgress();
            return false;
        }
        if (!app.searchdata.BinNum) {
            api.toast({
                msg: lan['BinNum_placeholder'],
                location: 'middle'
            });
            hideProgress();
            return false;
        }
        if (app.is_lot == 1) {
            if (!app.LotNum) {
                api.toast({
                    msg: lan['LotNum_placeholder'],
                    location: 'middle'
                });
                hideProgress();
                return false;
            }
        }
        if (app.is_SerialNum == 1) {
            if (app.SelectedSerialNumbers.length == 0) {
                api.toast({
                    msg: lan['Serialnum_placeholder'],
                    location: 'middle'
                });
                hideProgress();
                return false;
            }
        }
        if (ajaxing) { return; } showProgress(lan['Loading']);
        ajaxing = 1;
        var data1 = {
            "CompanyID": userinfo.Company,
            "PlantID": userinfo.Site,
            "UserName": userinfo.Name,
            "Password": userinfo.password,
            "TranDate": app.searchdata.ArrivedDate,
            "TranQty": processNumber(app.searchdata.Complete_Qty, app.searchdata.NumOfDec),
            "JobNum": app.searchdata.JobNum,
            "AssemblySeq": processNumber(app.searchdata.Assembly, app.searchdata.NumOfDec),
            "LotNum": app.LotNum,
            "WarehouseCode": app.searchdata.WareHouseCode,
            "BinNum": app.searchdata.BinNum,
        }


        var arr = [];
        for (k in app.SelectedSerialNumbers) {
            var snitem = app.SelectedSerialNumbers[k];
            delete snitem.xs;
            delete snitem.OnhandQty;
            delete snitem.type;
            delete snitem.tag;
            delete snitem.PalleLabel;
            arr.push(snitem);

        }
        console.log(JSON.stringify(app.SelectedSerialNumbers), 11111111)
        if (arr) {
            data1.SelectedSerialNumbers = {};
            data1.SelectedSerialNumbers.SelectedSerialNumbers = arr;
            data1.SelectedSerialNumbers.SNFormat = app.SNFormat;
        }
        console.log(JSON.stringify(data1), 1111111)
        api.ajax({
            url: wmsserver + 'jobtoinv/',
            method: 'post',
            returnAll: false,
            headers: {
                'token': wmstoken,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {
                body: create_submit_data(data1)
            }
        }, function (ret, err) {
            console.log(JSON.stringify(ret), 55555)
            ajaxing = 0;
            console_debug(ret, err);
            returncount++;
            if (ret && ret.code == 1) {
                var param = ret.data.PartTran[0];
                app.version = param.RevisionNum;
                console.log(JSON.stringify(tags), 66666)
                api.alert({
                    title: lan['Tips'],
                    msg: lan['Submitted_successfully']
                }, function (ret, err) {
                    $('#exampleModal').modal('hide');

                    app.create_btn = true;
                    app.comfirm_btn = true;

                });

                hideProgress();
            } else {
                app.comfirm_btn = true
                hideProgress();
                errMassage(ret.msg)
            }

        });



    }


   
    //批次属性接口
    function LotAttributeOption(item) {
        api.ajax({
            url: server + 'BaqSvc/WMS_LotAttributeOption/?CompID=' + userinfo.Company + '&PartNum=' + item.PartNum + '',
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {}
        }, function (ret, err) {
            ajaxing = 0;
            if (ret && ret.value.length > 0) {
                console.log(JSON.stringify(ret.value[0]), 666666)
                var keys = Object.keys(ret.value[0]);
                app.LotItem = ret.value[0];
                var allN = keys.filter(function (key) {
                    return key !== "Part_Company" && key !== "RowIdent";
                }).every(function (key) {
                    return ret.value[0][key] === "N";
                });
                if (allN) {
                    app.Batch_check = true;
                    app.receipt_check = false
                } else {
                    app.Batch_check = false;
                    app.receipt_check = true
                }

            }

        });
    }

    function GenerateNewLotNum(param) {
        var model = {
            "vPartNum": param.PartNum
        }

        api.ajax({
            url: server + 'Erp.BO.LotSelectUpdateSvc/GenerateNewLotNum',
            method: 'post',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {
                body: JSON.stringify(model)
            }
        }, function (ret, err) {
            ajaxing = 0;
            console_debug(ret, err);
            hideProgress();

            if (ret) {
                app.LotNum = ret.parameters.vNewLotNum;
                param.LotNum = ret.parameters.vNewLotNum;
                // submitfrom();

            } else {
                hideProgress();
                api.toast({
                    msg: lan['TrackLots_Error'],
                    location: 'middle'
                });
            }

        });
    }

</script>

</html>